package top.topsmart.api.bycenter.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeHandler {
    public String TimeHandler(Date date){
        double time = date.getTime();
        double now = new Date().getTime();
        double middle = now - time;


        //1分钟内 刚刚
        if (middle < 60000){
            return "刚刚";
        }
        //1小时内 xx分钟前
        else if (middle<3600000){
            double a = middle/60000;
            double b = Math.floor(a);
            Integer c = Integer.parseInt(new java.text.DecimalFormat("0").format(b));
            return c.toString() + "分钟前";
        }
        //1天内 xx小时前
        else if (middle<86400000){
            double a = middle/3600000;
            double b = Math.floor(a);
            Integer c = Integer.parseInt(new java.text.DecimalFormat("0").format(b));
            return c.toString() + "小时前";
        }
        //1天之前 2天之内 昨天
        else if (middle> 86400000 && middle<172800000){
            return "昨天";
        }
        else {
            DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd"); //HH表示24小时制；
            return dFormat.format(date).toString();
        }
    }
}
